package com.company.psm.entity;

import static javax.persistence.GenerationType.IDENTITY;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;


@Entity
@Table(name = "medicines")
public class Medicine implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 6676806709405455038L;

	private long id;
	private String name;
	private String description;
	private String price;
	private String quantity;
	private String imageLink;
	private String specialize;
	private String contraindicated;
	private List<Gradient> gradients;
	private Store store;
	private Category category;
	//private List<Bill> bills;
	
	
	
	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "ID", unique = true, nullable = false)
	public long getId() {
		return id;
	}
	public void setId(long id) {
		this.id = id;
	}
	
	@Column(name = "NAME", length = 200)
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	
	@Column(name = "DESCRIPTION", length = 200)
	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		this.description = description;
	}
	
	@Column(name = "PRICE", length = 200)
	public String getPrice() {
		return price;
	}
	public void setPrice(String price) {
		this.price = price;
	}
	
	@Column(name = "QUANTITY", length = 200)
	public String getQuantity() {
		return quantity;
	}
	public void setQuantity(String quantity) {
		this.quantity = quantity;
	}
	
	@Column(name = "IMAGELINK", length = 200)
	public String getImageLink() {
		return imageLink;
	}
	public void setImageLink(String imageLink) {
		this.imageLink = imageLink;
	}
	
	@ManyToMany(
			fetch = FetchType.EAGER,
	        //targetEntity=Gradient.class,
			cascade={}
	    )
	//@Fetch(value = FetchMode.SUBSELECT)
//    @JoinTable(
//	        name="gradients_medicines",
//	        joinColumns=@JoinColumn(name="MEDICINE_ID"),
//	        inverseJoinColumns=@JoinColumn(name="GRADIENT_ID")
//	    )    
	public List<Gradient> getGradients() {
		return gradients;
	}
	public void setGradients(List<Gradient> gradients) {
		this.gradients = gradients;
	}
	
	@ManyToOne
	public Store getStore() {
		return store;
	}
	public void setStore(Store store) {
		this.store = store;
	}
	
	@Column(name = "SPECIALIZE", length = 200)
	public String getSpecialize() {
		return specialize;
	}
	public void setSpecialize(String specialize) {
		this.specialize = specialize;
	}
	
	@Column(name = "CONTRAINDICATED", length = 200)
	public String getContraindicated() {
		return contraindicated;
	}
	public void setContraindicated(String contraindicated) {
		this.contraindicated = contraindicated;
	}
	
	@ManyToOne(fetch = FetchType.EAGER)
	public Category getCategory() {
		return category;
	}
	public void setCategory(Category category) {
		this.category = category;
	}

	
//	@ManyToMany(fetch = FetchType.EAGER, targetEntity = Bill.class, cascade = { CascadeType.REMOVE })
//	@Fetch(value = FetchMode.SUBSELECT)
//	@JoinTable(name = "Bills_Medicines", joinColumns = @JoinColumn(name = "Medicine_ID"), inverseJoinColumns = @JoinColumn(name = "Bill_ID"))
//	public List<Bill> getBills() {
//		return bills;
//	}
//	public void setBills(List<Bill> bills) {
//		this.bills = bills;
//	}
}
